#include "Rp2IndexBuffer.h"

using namespace Rp2;

RP2_IMPLEMENT_RTTI(Rp2, IndexBuffer, Object);
RP2_IMPLEMENT_DEFAULT_NAME_ID(IndexBuffer, Object);

//---------------------------------------------------------------------------------------------------
IndexBuffer::IndexBuffer(int iIndexQuantity)
{
	m_iID = 0;
	m_iOffset = 0;
	m_iIndexQuantity = iIndexQuantity;
	m_aiIndex = new int[m_iIndexQuantity];
	memset(m_aiIndex, 0, m_iIndexQuantity * sizeof(int));
}
//---------------------------------------------------------------------------------------------------
IndexBuffer::IndexBuffer(const IndexBuffer* pkIBuffer)
{
	m_iID = pkIBuffer->m_iID;
	m_iOffset = pkIBuffer->m_iOffset;
	m_iIndexQuantity = pkIBuffer->m_iIndexQuantity;
	m_aiIndex = new int[m_iIndexQuantity];
	memcpy(m_aiIndex, pkIBuffer->m_aiIndex, m_iIndexQuantity * sizeof(int));
}
//---------------------------------------------------------------------------------------------------
IndexBuffer::~IndexBuffer()
{
	Release();

	delete[] m_aiIndex;
}
//---------------------------------------------------------------------------------------------------
void IndexBuffer::PrintToFile(const char* acFilename)
{
	std::ofstream kOStr(acFilename);
	kOStr	<< "Index quantity: " << m_iIndexQuantity << std::endl;
	kOStr	<< "--------------------------------\n"
			<< "Index Data Begin\n"
			<< "--------------------------------\n";
	for (int i = 0; i < m_iIndexQuantity; i+=3)
	{
		kOStr << i/3 << "	: ("
			  << m_aiIndex[i]   << ", "
			  << m_aiIndex[i+1] << ", "
			  << m_aiIndex[i+2] << ")\n";
	}
	kOStr	<< "--------------------------------\n"
			<< "Index Data End\n"
			<< "--------------------------------\n";
	kOStr.close();
}
//---------------------------------------------------------------------------------------------------